package com.jcark.mvvm

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.jcark.mvvm.net.NetTestActivity
import me.hgj.mvvm.base.viewmodel.BaseViewModel
import me.hgj.mvvm.ext.view.animAlphaVisible
import me.hgj.mvvm.ext.view.animateWidthAndHeight
import me.hgj.mvvm.ext.view.dp2px
import me.hgj.mvvm.ext.view.getResourceColor
import me.hgj.mvvm.ext.view.getResourceFormatString
import me.hgj.mvvm.ext.view.margin

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val tvMessage = findViewById<TextView>(R.id.message)
        tvMessage.setTextColor(getResourceColor(R.color.red))
        var isVisible = true
        val buttonNetwork = findViewById<Button>(R.id.btn_net_test)
        buttonNetwork.setOnClickListener {
            startActivity(Intent(MainActivity@ this, NetTestActivity::class.java))
        }

        val btnTest = findViewById<Button>(R.id.btn_test)
        btnTest.setOnClickListener {
            tvMessage.text = getResourceFormatString(R.string.message_info, "Out")
            //tvMessage.text = String.format(getString(R.string.message_info), "Out")
            if (!isVisible) {
                tvMessage.setBackgroundColor(getResourceColor(R.color.purple_200))
                tvMessage.animateWidthAndHeight(dp2px(150f), dp2px(60f))
            }
            isVisible = !isVisible
            tvMessage.animAlphaVisible(isVisible)
            buttonNetwork.margin(top = dp2px(30f))
        }

        testCurrentPageIndex()
    }

    fun testCurrentPageIndex() {
        val viewModel = BaseViewModel()
        Log.d("KING", "init==${viewModel.currentPageIndex}")
        viewModel.currentPageIndex++
        Log.d("KING", "Index+1 ==${viewModel.currentPageIndex}")
        viewModel.revertCurrentPageIndex()
        Log.d("KING", "Index-1=1=${viewModel.currentPageIndex}")
        viewModel.revertCurrentPageIndex()
        Log.d("KING", "Index-1=2=${viewModel.currentPageIndex}")
    }
}

